<?php
class CMReams_Log
{
  var $logs;
  var $s;
  
  function CMReams_Log($table = "logs", $date = "date", $type="type", $text="text") {
    global $pfx;
    
    $table = $pfx.$table;
    $this->s = array('table'=>$table, 'date'=>$date, 'type'=>$type, 'text'=>$text);
    $this->logs = array();
  }
  
  function add($type, $text) {
    $this->logs[] = array($type, $text);
    return true;
  }
  
  function write()
  {
    if(count($this->logs)>0) {
      $sql = "INSERT INTO ".$this->s['table']." (`".$this->s['date']."`, `".$this->s['type']."`, `".$this->s['text']."`) VALUES ";
      $b = array();
      foreach($this->logs as $l) {
        $b[] = "('".time()."', '".gpcSQL($l[0])."', '".gpcSQL($l[1])."')";
      }
      $c = implode(", ", $b);
      $sql .= $c.";";
      if(!@mysql_query($sql)) {
        return false;
      }
    }
    return true;
  }
}

$glog = new CMReams_Log("logs", "date", "type", "text");
?>